package com.poobo.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.poobo.condiction.EquipmentConfigListCondiction;
import com.poobo.dao.IConfigListDao;
import com.poobo.dao.IEquipmentConfiglistDao;
import com.poobo.dao.IEquipmentDao;
import com.poobo.entity.TbConfigList;
import com.poobo.entity.TbEquipment;
import com.poobo.entity.TbEquipmentConfiglist;
import com.poobo.service.IEquipmentConfigListService;
import com.poobo.util.pager.Page;

@Service
@Transactional
public class EquipmentConfigListServiceImpl implements IEquipmentConfigListService {

	@Autowired
	private IEquipmentConfiglistDao equipmentConfiglistDao;
	@Autowired
	private IConfigListDao configListDao;
	@Autowired
	private IEquipmentDao equipmentDao;
	
	@Override
	public TbEquipmentConfiglist queryEquipmentConfigById(Integer id) {
		return equipmentConfiglistDao.queryEquipmentConfigById(id);
	}

	@Override
	public Page queryEquipmentConfigPage2(
			TbEquipmentConfiglist equipmentConfiglist, Page page) {
		return equipmentConfiglistDao.queryEquipmentConfigPage2(equipmentConfiglist, page);
	}

	@Override
	public void deleteEquipmentConfigById(Integer id) {
		equipmentConfiglistDao.deleteEquipmentConfigById(id);
	}

	@Override
	public void saveEquipmentConfig(TbEquipmentConfiglist equipmentConfiglist) {
		equipmentConfiglistDao.saveEquipmentConfig(equipmentConfiglist);
	}

	@Override
	public Page queryEquipmentConfigPage(
			EquipmentConfigListCondiction equipmentConfigListCondiction, Page page) {
		return equipmentConfiglistDao.queryEquipmentConfigPage(equipmentConfigListCondiction, page);
	}

	@Override
	public void deleteEquipmentConfigByEquipmentId(Integer eId) {
		equipmentConfiglistDao.deleteEquipmentConfigByEquipmentId(eId);
	}

	@Override
	public void deleteEquipmentConfigByConfigListId(Integer configListId) {
		equipmentConfiglistDao.deleteEquipmentConfigByConfigListId(configListId);
	}

	@Override
	public List<Map<String, String>> findEQCL() {
		List<TbEquipmentConfiglist> equipmentConfiglists = equipmentConfiglistDao.findAll();
		Map<String, String> map = new HashMap<String, String>(); 
		List<Map<String, String>> maps = new ArrayList<Map<String,String>>();
		TbEquipmentConfiglist equipmentConfiglist = null;
		TbEquipment equipment = null;
		TbConfigList configList = null;
		if( equipmentConfiglists != null && equipmentConfiglists.size() > 0 ){
			for( int i=0; i<equipmentConfiglists.size(); i++ ){
				equipmentConfiglist = equipmentConfiglists.get(i);
				equipment = equipmentDao.queryEquipmentById(equipmentConfiglist.getEid());
				configList = configListDao.queryConfigListById(equipmentConfiglist.getConfigListId());
				if( equipment !=null && configList != null ){					
					map.put("number", equipment.getNumber());
					map.put("txtURL", configList.getListUrl());
					maps.add(map);
				}
			}
		}
		return maps;
	}

	@Override
	public TbEquipmentConfiglist queryEquipmentConfigByEqId(Integer eid) {
		return equipmentConfiglistDao.queryEquipmentConfigByEqId(eid);
	}

}
